/*
 * License: Copyright (c) Huawei Technologies Co., Ltd. 2012-2019. All rights reserved.
 * Description: push stream
 * Date: 2020-01-07 09:50:36
 * LastEditTime : 2020-01-07 11:04:13
 */

#ifndef DEST_ENGINE_H
#define DEST_ENGINE_H
#include <thread>
#include <deque>
#include <mutex> 
#include "hiaiengine/engine.h"
#include <stdio.h>
#include "trans_data.h"

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libswscale/swscale.h>
#include <libswscale/swscale.h>
}

#define DE_INPUT_SIZE 1
#define DE_OUTPUT_SIZE 1
class DestEngine : public hiai::Engine {
public:
    HIAI_StatusT Init(const hiai::AIConfig& config, const std::vector<hiai::AIModelDescription>& model_desc);

    HIAI_StatusT AvInit(std::shared_ptr<TransData> rawDataInput);

    uint64_t GetCurentTimeStamp();

    ~DestEngine();


    HIAI_DEFINE_PROCESS(DE_INPUT_SIZE, DE_OUTPUT_SIZE)
private:
    void StreamOutputThread();
    std::thread streamOutputRunner;
    std::deque<std::shared_ptr<TransData>> transDataQueue;
    std::mutex dequeMutex;

    AVFormatContext* pOutFormatCtx = NULL;
    AVStream* pOutStream = NULL;
    AVCodecParameters *pOutCodecPar = NULL;

    bool isAvInitSuccess = true;
    bool isHeaderWrite = false;
    bool stop = false;

};

#endif
